const searchWord = require('./rest/searchWord')

module.exports = {
    'GET /rest/search' : require('./rest/search.json'),
    'GET /rest/searchWord'(req,res){
        const {pageNumber, pageSize} = req.query
        const index = pageNumber * pageSize 
        return res.json( {tableData : searchWord.slice(index,  + pageSize + index), total: 357})
    },
    'GET /rest/wordcloud': require('./rest/wordcloud.json'),
    'GET /rest/map'(req,res) {
       const data =  require('./rest/map.json')
       data.scatterData = data.scatterData.map(item => {
            const {name,value} = item
            value.push(Math.random() * 100 + 50)
            return {name,value}
        }).sort(function (a, b) {
            return b.value[2] - a.value[2]
        })
       return  res.json(data)
    },
    'GET /rest/liquidFill'(req,res){
        return res.json({percent: 0.3921})
    },
    'GET /rest/totalSales'(req,res){
        const data = {
            salesToday : 32231412,
            salesGrowthLastDay: 0.733,
            salesGrowthLastMonth: 0.421,
            salesLastDay: 4125215
        }
        return res.json(data)
    },
    'GET /rest/totalOrder' : require('./rest/totalOrder.json'),
    'GET /rest/todayUsers' : require('./rest/todayUsers.json'),
    'GET /rest/totalUsers'(req,res){
        const data = {
            userGrowthLastDay : 0.3125,
            userGrowthLastMonth: 0.1542,
            userTodayNumber: 300,
            userLastMonth: 200,
            userToday : 33124234
        }
        return res.json(data)
    },
    'GET /rest/yearSales'(req,res){
        const data = [{
            title: '年度销售额',
            data: [214, 125, 623, 612, 216, 141, 614, 626, 146, 146, 141, 616]
        },{
            title: '年度访问量',
            data: [421, 521, 574, 617, 140, 631, 861, 421, 446, 404, 500, 301]
        }]
        return res.json(data[req.query.index])
    },
    'GET /rest/rankData'(req,res){
        const active = req.query.index;
        const static =  [
               '麦当劳',
               '肯德基',
               '北京烤鸭',
               '海底捞',
               '黄焖鸡',
               '兰州拉面',
               '重庆鸡公煲',
               '汉堡王',
               '好好吃',
          ]
         const data =  static.map(item=>{
             return {name: item,money :  item.charCodeAt() * active  / 37 % 37219 | 0}
         }).sort((a,b)=> b.money - a.money).map((item,index)=>{
             return {...item,no: index+1}
         })
        return res.json(data)
    },
    'GET /rest/pieData': require('./rest/pie.json')


};